package order;

import pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-03-15
 * Time: 20:16
 */

public class OrderPizza {

    AbsFactory absFactory;


    //构造器
    public OrderPizza(AbsFactory factory){
        setAbsFactory(factory);
    }


    public void setAbsFactory(AbsFactory factory){
        Pizza pizza = null;
        String oderType = "";
        this.absFactory = factory;

        do {
            oderType = getType();
            //factory 可能是北京的 也可能是伦敦的 取决于接口传的什么就是什么
            pizza = factory.createPizza(oderType);
            if (pizza != null){
                //订购成功
                pizza.prepare();;
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购失败");
            }
        }while (true);

    }

    //写一个方法 可以获取用户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }

}
